< previous page page_56 next page >

Page 56
note.gif You can select a Startup Form in the Project Properties dialog box. You also can have a program start from a sub procedure named Main in a code module rather than from a form. square.gif

However, if you have multiple formsas most programs doyou need to understand how to manage them. The state of a form is controlled by Visual Basic's Load and Unload statements as well as the form's Show and Hide methods.
The Load statement places a form in memory but does not display it. The following line of code shows how the statement is used:
Load frmApplication
By using this statement, you are explicitly loading the form. However, the form is loaded automatically if you access a property, method, or control on it. Because the load operation is performed automatically, using the Load statement with a form is not really necessary. However, being aware when a form is being loaded is important because the code in the Form_Load event will be executed at that time.
To display a form other than the Startup Form, you must use the Show method. The Show method works whether or not the form was loaded previously into memory. If the form was not loaded, the Show method implicitly loads the form and then displays it. The Show method is used as follows:
frmApplication.Show
The Show method also has an optional argument that determines whether the form is shown as a modal or modeless form. If a form is shown modally (a modal form), then program control doesn't return to the procedure that called the Show method until the modal form is closed. Think of the program code as being paused as long as a modal form is displayed. An example of a modal form is the Windows 95 Shutdown screen. You cannot put the focus on another window while the Shut Down Windows form is displayed.
If a form is shown modeless, your program's users can move at will between the current form and other forms in the program. The preceding statement displayed a form as modeless. To create a modal form, you simply set the optional argument of the Show method to vbModal, as shown here:
frmApplication.Show vbModal
note.gif A modal form is typically used when you want the users to complete the actions on the form before working on any other part of the program. For example, if a critical error occurs, you do not want the users to switch to another form and ignore it. square.gif

After a form is displayed, you have two choices for getting rid of it programmatically. The Hide method removes the form from the screen but does not remove it from memory. Use Hide when you need to remove the form from view temporarily but still need information in it:
frmApplication.Hide
sUserName = frmApplication.txtUserName.Text

 
< previous page page_56 next page >